package mapreduce.wordcount;

import org.apache.hadoop.io.LongWritable;
import org.apache.hadoop.io.Text;
import org.apache.hadoop.mapreduce.Mapper;

import java.io.IOException;

/**
 *继承Mapper类，在其map方法中编写业务逻辑。将k1，v1转为k2，v2
 * 有四个泛型类型:<KEYIN,VALUEIN,KEYOUT,VALUEOUT>，就是k1,v1,k2,v2.
 */
public class WordCountMapper extends Mapper<LongWritable, Text, Text, LongWritable> {
    /**
     *
     * @param key    K1    LongWriter、Text相当于long、String，是hadoop中的封装类型
     * @param value    V1
     * @param context
     */
    @Override
    protected void map(LongWritable key, Text value, Context context) throws IOException, InterruptedException {
        String line = value.toString();
        String[] splitLine = line.split(",");

        for (String word : splitLine){
            context.write(new Text(word), new LongWritable(1));
        }
    }
}
